//
//  KFDMarketInfoContainerModel.m
//  
//
//  Created by JIRENTIANXIANG on 6/13/15.
//
//

#import "KFDMarketInfoContainerModel.h"
#import "KFDClient.h"

@implementation KFDMarketInfoContainerModel

-(void)loadFinancialCalendardDates
{
    KFDClient* client=[KFDClient sharedClient];
    [client getFinancialCalendarDatesWithSuccessHandler:^(NSArray *dates) {
        self.weekdays=dates;
    } failureHandler:^(KFDResponseBody *response) {
        
    }];
}

-(void)loadAliveNewsWithMaxCount:(NSUInteger)count page:(NSUInteger)page
{
    NSUInteger oldCount=self.aliveNews.count;
    KFDClient* client=[KFDClient sharedClient];
    [client getLiveNewsWithMaxCountPerPage:count page:page successHandler:^(NSArray *aliveNews) {
        self.aliveNews=aliveNews;
        [[NSNotificationCenter defaultCenter] postNotificationName:KFDMarketNewsAliveTableViewDataSourceReadyNotification object:nil userInfo:@{@"countIncrement":@(self.aliveNews.count-oldCount)}];
    } failureHandler:^(KFDResponseBody *response) {
        
    }];
}

-(void)loadTradingStrategiesWithMaxCount:(NSUInteger)count page:(NSUInteger)page
{
    NSUInteger oldCount=self.tradingStrategies.count;
    KFDClient* client=[KFDClient sharedClient];
    [client getTradingStrategiesWithMaxCountPerPage:count page:page successHandler:^(NSArray *tradingStrategies) {
        self.tradingStrategies=tradingStrategies;
        [[NSNotificationCenter defaultCenter] postNotificationName:KFDMarketTradingStrategyTableViewDataSourceReadyNotification object:nil userInfo:@{@"countIncrement":@(self.tradingStrategies.count-oldCount)}];
    } failureHandler:^(KFDResponseBody *response) {
        
    }];
}

-(void)loadFinancialInfoWithDate:(NSDate *)date
{
    KFDClient* client=[KFDClient sharedClient];
    [client getFinancialInfoWithDate:date successHandler:^(NSArray *financialData, NSArray *holidayForecasts, NSArray *financialEvents) {
        self.financialData=financialData;
        self.holidayForecasts=holidayForecasts;
        self.financialEvents=financialEvents;
        [[NSNotificationCenter defaultCenter] postNotificationName:KFDMarketFinanceCalendarTableViewDataSourceReadyNotification object:nil];
    } failureHandler:^(KFDResponseBody *response) {
        
    }];
}

@end
